package cn.jiuxiaoer.job.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zglu
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // 新增的时候自动填充
        this.setFieldValByName("createDate", new Date(), metaObject);
        this.setFieldValByName("lastModifiedDate", new Date(), metaObject);
        this.setFieldValByName("createBy", "过期预警定时任务", metaObject);
        this.setFieldValByName("createdName", "过期预警定时任务", metaObject);
        this.setFieldValByName("lastModifiedBy", "过期预警定时任务", metaObject);
        this.setFieldValByName("lastModifiedName", "过期预警定时任务", metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 更新的时候自动填充
        this.setFieldValByName("lastModifiedDate", new Date(), metaObject);
        this.setFieldValByName("lastModifiedBy", "过期预警定时任务", metaObject);
        this.setFieldValByName("lastModifiedName", "过期预警定时任务", metaObject);
    }
}
